﻿#include "BaseCommunication.h"

BaseCommunication::BaseCommunication(QObject *parent):BaseItem(parent)
{

}

void BaseCommunication::SetCommunicationParam(QString communicationParam)
{
//    _communicationParam=communicationParam;
}

QString BaseCommunication::getCommParam()
{
    return _obj["address"].toString();
}

bool BaseCommunication::connectToHost()
{
    return true;
}

bool BaseCommunication::isConnected()
{
    return true;
}

bool BaseCommunication::disConnect()
{
    return true;
}


QWidget* BaseCommunication::getConfigWidget()
{
    QDialog *w=new QDialog();
    return w;
}

void BaseCommunication::setConfig(QJsonObject obj)
{
    BaseItem::setConfig(obj);
    if(obj["Address"].isString())
    {
        SetCommunicationParam(obj["Address"].toString());
    }
    else
    {
        QJsonDocument jsonDoc(obj["Address"].toObject());
        QString jsonString = jsonDoc.toJson(QJsonDocument::Compact);
        SetCommunicationParam(jsonString);
    }
}

bool BaseCommunication::init()
{
    return true;
}
